package com.tuanda.app.customviewdemo.paint;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BlurMaskFilter;
import android.graphics.Canvas;
import android.graphics.EmbossMaskFilter;
import android.support.annotation.Nullable;
import android.util.AttributeSet;

import com.tuanda.app.customviewdemo.BaseCustomView;
import com.tuanda.app.customviewdemo.R;

/**
 * Created by LiDongduo on 2018/9/21.
 */
public class PaintMaskFilterView extends BaseCustomView {
    public PaintMaskFilterView(Context context) {
        super(context);
    }

    public PaintMaskFilterView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public PaintMaskFilterView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void initData() {
        setLayerType(LAYER_TYPE_SOFTWARE,null);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_trump);
        mPaint.setMaskFilter(new BlurMaskFilter(50, BlurMaskFilter.Blur.NORMAL));
        canvas.drawBitmap(bitmap,50,50,mPaint);

        mPaint.setMaskFilter(new EmbossMaskFilter(new float[]{0,1,3},0.5f,10,20 ));
        canvas.drawBitmap(bitmap,100+bitmap.getWidth(),50,mPaint);
    }
}
